package com.yunbiao.ybbusstopplate.serialport

import android.util.Log

class SerialPortConfig {
    companion object{
//        var UART_PATH="/dev/uart_dev/UART_485"
        const val TYPE_TD=1
        const val TYPE_TD2020=2
        const val TYPE_TK=3
        const val TYPE_HY=4
        const val TYPE_LS=5
        const val TYPE_HX=6
        const val TYPE_TM=7
        const val TYPE_LTY=8
        const val TYPE_LSTK=9
        const val TYPE_ZHX=10


        var UART_PATH_ttys1 = "/dev/ttyS1"
        var UART_PATH_ttys2 = "/dev/ttyS2" // 40a
        var UART_PATH_ttys3 = "/dev/ttyS3" // 3568HV
        var UART_PATH_ttys7 = "/dev/ttyS7"

        var finalPath = UART_PATH_ttys2

        var PORT_TYPE=TYPE_TD //1:通达2018 2:通达2020 3：通卡 4：恒宇 5:蓝斯 6:海信 7:天迈 8:蓝泰源
        var UART_PATH= finalPath
        var BAUDRATE=38400
        var PORT_NAME="通达"

        //0:通达 1：通卡 2：恒宇 3:蓝斯 4:海信 5:天迈
        var PORTNAMES= arrayListOf<String>("通达2018","通达2020","通卡","恒宇","蓝斯","海信","天迈","蓝泰源","蓝斯TK","中航讯")
        var PORTTYPES= arrayListOf<Int>(TYPE_TD,TYPE_TD2020,TYPE_TK,TYPE_HY,TYPE_LS,TYPE_HX,TYPE_TM,TYPE_LTY,TYPE_LSTK,TYPE_ZHX)

        fun init(type:Int){
            if (type<=0){
                return
            }
            when(type){
                TYPE_TD->{
                    initPortByTD()
                }
                TYPE_TD2020->{
                    initPortByTD2020()
                }

                TYPE_TK->{
                    initPortByTK()
                }

                TYPE_HY->{
                    initPortByHY()
                }

                TYPE_LS->{
                    initPortByLS()
                }

                TYPE_LSTK->{
                    initPortByLSTK()
                }

                TYPE_HX->{
                    initPortByHX()
                }

                TYPE_TM->{
                    initPortByTM()
                }

                TYPE_LTY->{
                    initPortByLTY()
                }

                TYPE_ZHX->{
                    initPortByZHX()
                }
            }
            Log.e("SerialPortConfig", "init: 当前协议类型：$PORT_TYPE")
            Log.e("SerialPortConfig", "init: 当前协议名：$PORT_NAME")
            Log.e("SerialPortConfig", "init: 当前串口地址：$UART_PATH")
            Log.e("SerialPortConfig", "init: 当前波特率：$BAUDRATE")
        }

        fun initPortByTD(){
            PORT_TYPE= PORTTYPES[0]
            PORT_NAME= PORTNAMES[0]
            UART_PATH= finalPath
            BAUDRATE=38400
        }

        fun initPortByTD2020(){
            PORT_TYPE= PORTTYPES[1]
            PORT_NAME= PORTNAMES[1]
            UART_PATH=finalPath
            BAUDRATE=38400
        }

        fun initPortByTK(){
//            PORT_TYPE= TYPE_TK
//            PORT_NAME="通卡"
            PORT_TYPE= PORTTYPES[2]
            PORT_NAME= PORTNAMES[2]
            UART_PATH=finalPath
            BAUDRATE=38400
        }

        fun initPortByHY(){
//            PORT_TYPE= TYPE_HY
//            PORT_NAME="恒宇"
            PORT_TYPE= PORTTYPES[3]
            PORT_NAME= PORTNAMES[3]
            UART_PATH=finalPath
            BAUDRATE=9600
        }

        fun initPortByLS(){
//            PORT_TYPE= TYPE_LS
//            PORT_NAME="蓝斯"
            PORT_TYPE= PORTTYPES[4]
            PORT_NAME= PORTNAMES[4]
            UART_PATH=finalPath
            BAUDRATE=9600
        }

        fun initPortByHX(){
//            PORT_TYPE= TYPE_LS
//            PORT_NAME="蓝斯"
            PORT_TYPE= PORTTYPES[5]
            PORT_NAME= PORTNAMES[5]
            UART_PATH=finalPath
            BAUDRATE=19200
        }

        fun initPortByTM(){
            PORT_TYPE= PORTTYPES[6]
            PORT_NAME= PORTNAMES[6]
            UART_PATH=finalPath
            BAUDRATE=9600
        }

        fun initPortByLTY(){
            PORT_TYPE = PORTTYPES[7]
            PORT_NAME = PORTNAMES[7]
            UART_PATH=finalPath
            BAUDRATE=9600
        }

        fun initPortByLSTK(){
            PORT_TYPE= PORTTYPES[8]
            PORT_NAME= PORTNAMES[8]
            UART_PATH=finalPath
            BAUDRATE=38400
        }

        fun initPortByZHX(){
            PORT_TYPE= PORTTYPES[9]
            PORT_NAME= PORTNAMES[9]
            UART_PATH= finalPath
            BAUDRATE=9600
        }
    }
}